/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-02-10
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-03-01
 * @Description: 
 */
// 显示图片预览的弹窗
import 'package:chat_client/providers/individual_provider.dart';
import 'package:flutter/material.dart';

import 'package:chat_client/screens/mobile/widgets/c_popup_bottom.dart';
import 'package:provider/provider.dart';

//  用于移动端的图片预览页面
class ImagePreviewPage extends StatelessWidget {
  final VoidCallback updateAvatar;

  const ImagePreviewPage({super.key, required this.updateAvatar});

  @override
  Widget build(BuildContext context) {
    final model = Provider.of<IndividualProvider>(context);

    return Scaffold(
      appBar: AppBar(
        title: const Text(
          '头像',
          style: TextStyle(
            color: Colors.white, // 设置标题文字颜色为白色
          ),
        ),
        leading: IconButton(
          icon: Icon(Icons.arrow_back, color: Colors.white),
          onPressed: () {
            Navigator.pop(context); // 返回上一页
          },
        ),
        actions: [
          IconButton(
            onPressed: () {
              // 父组件中调用
              BottomMenu.showBottomMenu(
                context,
                [
                  BottomMenuItem(
                    title: "从手机相册选择",
                    icon: Icons.photo_library,
                    onTap: () {
                      updateAvatar();
                      Navigator.pop(context);
                    },
                  ),
                  BottomMenuItem(
                    title: "保存到手机",
                    icon: Icons.download,
                    onTap: () {
                      // 处理保存到手机的逻辑
                      Navigator.pop(context);
                    },
                  )
                ],
              );
            },
            icon: Icon(Icons.more_horiz),
            color: Colors.white,
          ),
        ],
        backgroundColor: Colors.black,
      ),
      body: Container(
        color: Colors.black, // 设置整个页面背景为黑色
        child: Center(
          child: Container(
            width: double.infinity,
            color: Colors.white,
            child: model.avatarUrl.isEmpty
                ? const Icon(Icons.error) // 如果没有图片，显示错误图标
                : Image.network(
                    model.avatarUrl,
                    fit: BoxFit.contain,
                  ),
          ),
        ),
      ),
    );
  }
}
